home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 2 / LSD and 17bit Compendium Deluxe - Volume II.iso / a / prog / asmsrc / phagexsources.lha / shootemup / Tutorial.TXT < prev   
Encoding:
Text File  |  1993-08-21  |  8.2 KB  |  150 lines

  1. How to write a Shoot 'em Up, by Phagex of LSD.
  2.  
  3. The source code for this tutorial should be hanging around one of the
  4. Grapevine disks, and is self exctracting:   GameTut.EXE
  5.  
  6. Right, this is a tutorial for all the coders out there who have learnt how
  7. to put a screen on and make a few bobs fly around, but havent got an idea
  8. about how to put them to proper use. In this tutorial i have coded the basic
  9. platform (Nooo! not a PLATFORM game!  (it isnt a PLATFORM game is it?)) of
  10. a shoot 'em up.  Its a very simple move yer space ship around the screen, 
  11. and shoot upwards against the nasty alien coming down at you type affair,
  12. only its a complete, fully commented source code that i've given you to play
  13. with.  I've placed this game into the Public domain through Grapevine, but
  14. i have FULL copyright on this game, ie. the GFX and source.  I know it isnt
  15. that much, but i'de prefer you to draw and eventually program your OWN
  16. routines instead of just lifting them from my source, although it really
  17. isnt the BEST source anyway!  But it does do the job (which is all that
  18. matters when your coding for a living hehe!)...
  19.  
  20.  
  21. Anyway, off we go with a loose description of what happens:
  22.  
  23. First of all you naturally kill the system and set the games variables,
  24. then we have a few presentation routines for fading in and out and
  25. displaying text.  Start off with "Get Ready" and then head for the main
  26. game processing loop which is what i'll now describe in more detail...
  27.  
  28. First of all, the screen is double buffered, which i'm sure you all know the
  29. purpose of, (y'know, keeps everything smooth and flicker free) not only does
  30. this mean that the screen has two memory banks, but all variables associated
  31. with the blitting and clearing are double buffered as well.
  32.  
  33. The Aliens, Bullets and Explosions all have three data lists each, the first
  34. is the Variable Table which stores main variables about each item, and then
  35. theres 2 tables (double buffered) which stores the actual items Screen memory
  36. address, this is to allow for blitter clearing on the next frame.
  37.  
  38. The Variable Tables are used differently for each type of on screen object,
  39. each alien has 4 words allocated to it, the 1ST is the downwards SPEED
  40. (ie. this variable is added to the aliens Y Position), the 2ND and 3RD are 
  41. the X and Y Positions, and the 4TH is its animation FRAME.  The SPEED 
  42. variable is also used as an active FLAG, ie. if the speed is -1 ($ffff) then
  43. that particular alien is inactive (not shown), but if its positive ie. 1++
  44. then the alien IS active and is used as the speed.  Bullets are simpler in 
  45. the way they just have 2 words, X & Y Positions, but if the X Position is -1
  46. (Off screen) then its inactive and not shown.  Explosions have 3 words, an 
  47. X & Y and an animation Frame, similar to the bullet configuration.  
  48.  
  49.  
  50. Now the first thing i've done at the start of the loop is to clear all the
  51. old objects such as the ship, aliens, bullets (fire) and explosions off the
  52. screen, this is done by storing the memory positions of everything on screen
  53. in the last frame.  Then the clear routine just has to look up the last
  54. active objects and BlitClear them, this individual clearing is faster than
  55. clearing the WHOLE screen with the blitter.
  56.  
  57. The next 2 routines service the bullets, first the bullets variable table
  58. is scanned, any active bullets are moved UP the screen by subtracting a
  59. speed variable from the bullets Y Position, if however the bullet reaches
  60. the top of the screen then its life is over and that bullet is disactivated
  61. in the VarList.  The next routine blits the bullets onto the currently
  62. active screen.  This is done by scanning the VarList for active bullets
  63. (X Pos <> -1) and just blitting onto the screen with any active bullets X & Y
  64. positions.
  65.  
  66. Next are the alien routines, first a quick randomize routine which uses a
  67. few sources of varied numbers ie. X & Y Position of spaceship, raster X & Y
  68. position and contents of the KickStart ROM chip.  The new random number is
  69. used as the new X position and for the speed of any new aliens activated.
  70. The second routine is the New Alien one, every 10 frames a new alien is
  71. activated, the routine searches down the aliens VarList for an empty
  72. location (ie. unactive alien) and the first empty location it finds it puts
  73. the random number into the X Position (within screen boundaries), zeros the
  74. Y position and animation frame, and uses the remainder of the random number
  75. as the new aliens speed. This sets a new active alien into the VarList.  The
  76. third alien routine moves the aliens down the screen, same as the bullet
  77. mover works, but in the opposite direction.  When the alien reaches the
  78. bottom of the screen, it is then disactivated.  The fourth routine is a
  79. collision detection routine, it uses the VarLists of both the Bullets and
  80. the Aliens, its checks the X & Y Positions of all active bullets against
  81. all active aliens.  If any bullets co-ords are found within an aliens, then
  82. the alien is disactivated, score is increased and the New Explosion routine
  83. is called.  The explosion routine searches through its VarList for an unused
  84. explosion, gives the dead aliens X & Y Pos for a new explosions co-ords, and
  85. sets the frame to 0.  The fifth routine is just a blitter routine, goes
  86. through the Aliens VarList, blitting any alien active.
  87.  
  88. Next are the 2 explosion routines, the first just scans the explosion
  89. VarList and increases the Animation Frame number of any active explosions.
  90. When the frame counter of any explosion reaches 18, that explosion is
  91. disactivated as its reached its last anim frame. Second routine just blits
  92. the explosions current anim frames at their corresponding X & Y Pos.
  93.  
  94. Next is a quick check to see if the spaceship has been hit, and if its in
  95. the process of "dying" then the next few routines are skipped.
  96.  
  97. The CheckAlien routine is the other collision detection routine, where
  98. co-ords of active aliens are checked against the spaceships X & Y Pos. If
  99. the ship has collided, then an explosion is activated and a flag set to
  100. indicate death.  TrackStick and TrackMouse just get the status of the
  101. joystick and mouse and set the movement flags accordingly.  The MoveShip
  102. routine checks the movement flags and moves the ship Up/Down/Left/Right at
  103. the selected ship speed, it also checks the ships co-ords against the screen
  104. boundaries, and makes sure the ship doesnt wander off the edge of the screen!
  105.  
  106. Then the ships X & Y co-ords are Double buffered into either 1 of two sets
  107. according to what screen the ship will be displayed on.
  108.  
  109. Finally the SpaceShip is blitted onto the screen.
  110.  
  111. Then we wait for the Vertical Blank period, then double buffer the screen
  112. and copperlist, and increase the time variables.
  113.  
  114. A quick check to see if all the lives have been used up by the player, if
  115. they have then jump to the "Game Over" routines and exit, otherwise check
  116. the right mouse button, if pressed then quit anyway, else jump back to the
  117. mainloop!!
  118.  
  119.  
  120. And thats just about it!  Well its a fairly complex process, but hopefully
  121. you've learnt the basics of it all.  Theres quite a bit you can improve on,
  122. like the aliens, all they do is come down the screen at you, it shouldnt be
  123. too hard to make a routine where they follow a pattern, go left and right,
  124. in a circle or even both!  Then theres intelligence routines, aliens that
  125. follow you or avoid you.  Perhaps even a scrolly background that moves
  126. down the screen, complete with level maps and such.  Theres plenty of ideas
  127. to add to it all.  But remember to keep your source code simple and clean,
  128. it helps to be able to read and understand source that you coded while in
  129. a "different" state of mind like you were the other night hehe!
  130.  
  131. Oh, i coded this game in Devpac 3.02, and i recommend you use it or a Devpac
  132. variant for source compatability, i dunno about this ASM-one and Trashm
  133. business.  Devpac isnt the best, but i think its the most user friendly.
  134.  
  135.  
  136. As for future tutorials from me, well i'll keep 'em simple because i'm
  137. coding Satan On Speed for LSD and thats using ALL my free time up!  But i
  138. may even come up with a tutorial on platform games, but then again, WHO
  139. HASNT CODED A PLATFORM GAME!!! There are just SOOO many!!!  But i suppose
  140. theres always room for a GOOD platformer, most i've seen today are just
  141. simply shite.
  142.  
  143. Also i'm upping quite a bit of my source code to Pazzas BBS, so when its
  144. online you can leech my codings heh, but dont go bothering Pazza for my code
  145. pleeze....    cya 4 now....
  146.  
  147.  
  148.  
  149.  
  150.